package red.lsk.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import red.lsk.common.annotation.Log;
import red.lsk.common.enums.BusinessType;
import red.lsk.business.domain.BizDiscountConfig;
import red.lsk.business.service.IBizDiscountConfigService;
import red.lsk.common.core.controller.BaseController;
import red.lsk.common.core.domain.AjaxResult;
import red.lsk.common.utils.poi.ExcelUtil;
import red.lsk.common.core.page.TableDataInfo;

/**
 * 充值规则管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-09
 */
@Controller
@RequestMapping("/business/config")
public class BizDiscountConfigController extends BaseController
{
    private String prefix = "business/config";

    @Autowired
    private IBizDiscountConfigService bizDiscountConfigService;

    @RequiresPermissions("business:config:view")
    @GetMapping()
    public String config()
    {
        return prefix + "/config";
    }

    /**
     * 查询充值规则管理列表
     */
    @RequiresPermissions("business:config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizDiscountConfig bizDiscountConfig)
    {
        startPage();
        List<BizDiscountConfig> list = bizDiscountConfigService.selectBizDiscountConfigList(bizDiscountConfig);
        return getDataTable(list);
    }

    /**
     * 导出充值规则管理列表
     */
    @RequiresPermissions("business:config:export")
    @Log(title = "充值规则管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizDiscountConfig bizDiscountConfig)
    {
        List<BizDiscountConfig> list = bizDiscountConfigService.selectBizDiscountConfigList(bizDiscountConfig);
        ExcelUtil<BizDiscountConfig> util = new ExcelUtil<BizDiscountConfig>(BizDiscountConfig.class);
        return util.exportExcel(list, "充值规则管理数据");
    }

    /**
     * 新增充值规则管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存充值规则管理
     */
    @RequiresPermissions("business:config:add")
    @Log(title = "充值规则管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizDiscountConfig bizDiscountConfig)
    {
        return toAjax(bizDiscountConfigService.insertBizDiscountConfig(bizDiscountConfig));
    }

    /**
     * 修改充值规则管理
     */
    @RequiresPermissions("business:config:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BizDiscountConfig bizDiscountConfig = bizDiscountConfigService.selectBizDiscountConfigById(id);
        mmap.put("bizDiscountConfig", bizDiscountConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存充值规则管理
     */
    @RequiresPermissions("business:config:edit")
    @Log(title = "充值规则管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizDiscountConfig bizDiscountConfig)
    {
        return toAjax(bizDiscountConfigService.updateBizDiscountConfig(bizDiscountConfig));
    }

    /**
     * 删除充值规则管理
     */
    @RequiresPermissions("business:config:remove")
    @Log(title = "充值规则管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizDiscountConfigService.deleteBizDiscountConfigByIds(ids));
    }
}
